/*
 * @Descripttion: Lutongli代码
 * @version: 1.0.0
 * @Author: LutongLi
 * @Date: 2025-06-02 01:19:49
 * @LastEditTime: 2025-06-04 23:49:55
 */
package http

import (
	"github.com/gin-gonic/gin"

	"gitee.com/king_max/restful-api-demo/apps"
	"gitee.com/king_max/restful-api-demo/apps/host"
)

var (
	handler = &Handler{}
)

//通过写一个实例类，来处理HTTP协议，通过HTTP协议暴露出去
//需要内部接口的实现
//该实体类会实现一个http handler
type Handler struct{
	svc host.Service
}

// func NewHostHTTPHandler(svc host.Service) *Handler {
// 	return &Handler{
// 		svc:svc,
// 	}
// }
func NewHostHTTPHandler() *Handler {
	return &Handler{}
}

func (h *Handler) Config(){
	// if apps.HostService == nil{
	// 	panic("dependence host service required")
	// }
	// //从IOC里面获取Hostservice实例对象
	// h.svc = apps.HostService
	// return

	h.svc = apps.GetImpl(host.AppName).(host.Service)
	
}

func (h *Handler)Regsitry(r gin.IRouter){
	r.POST("/hosts",h.createHost)
}

func  (h *Handler) Name() string{
	return host.AppName
}


func init(){
	apps.RegsitryGin(handler)
}
